package se.webbzon.boltzmann.effect;

import se.webbzon.boltzmann.game.character.AbstractCharacter;
import se.webbzon.oschi01.worldarea.WorldArea;

public class CharacterShrinkingEffect extends CharacterEffect {
	
	// The original size of the character 
	double width, height, depth;
	
	// The original y-position of the character
	double y;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a character spinning effect which spins the given character
	 * during the given duration (in number of steps). **/
	public CharacterShrinkingEffect(AbstractCharacter character, int duration) {
		super(character,duration);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onEffectBegin(WorldArea world) {
		final AbstractCharacter character = getCharacter();
		
		width = character.getWidth();
		height = character.getHeight();
		depth = character.getDepth();
		y = character.getY();
	}

	@Override public void onEffectStep(WorldArea world) {
		final double scale = getDuration() / (double) getStartupDuration();
		final AbstractCharacter character = getCharacter();
		
		character.setSize(width * scale, height * scale, depth * scale);
		character.setPosition(character.getX(), y - (1-scale) * height, character.getZ());
	}

	@Override public void onEffectEnd(WorldArea world) {
		
	}
	
}
